package com.jiangroom.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName RabbitConfig
 * @Author chen.pian
 * @Date 2019/8/16 10:02
 **/
@Configuration
public class RabbitConfig {
    @Bean("testc")
    public Queue testc() {
        return new Queue("test.c");
    }

    @Bean("testd")
    public Queue testb() {
        return new Queue("test.d");
    }

    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanoutExchange");
    }

    @Bean
    public Binding bindingExchangeWithC(@Autowired @Qualifier("testc") Queue testa, @Autowired FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(testa).to(fanoutExchange);
    }

    @Bean
    public Binding bindingExchangeWithB(@Autowired @Qualifier("testd") Queue testb, @Autowired FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(testb).to(fanoutExchange);
    }
}
